package com.test.daily.leetcode.y2022.m07.day0728.v01;

import java.util.Arrays;
import java.util.HashMap;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/7/28 上午 10:32
 * @version: 1.0
 */
public class Solution {
    public int[] arrayRankTransform(int[] arr) {
        int N = arr.length;
        int[] arrSorted = new int[N];
        System.arraycopy(arr, 0, arrSorted, 0, N);
        Arrays.sort(arrSorted);
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            if(!map.containsKey(arrSorted[i])){
                map.put(arrSorted[i], map.size() + 1);
            }
        }
        int[] ans = new int[N];
        for (int i = 0; i < N; i++) {
            ans[i] = map.get(arr[i]);
        }
        return ans;
    }
}
